package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @PostMapping("/list")
    public Map<String, Object> list(Integer page, Integer rows, String customerName ) {
        Map<String, Object> resultMap = new HashMap<>();
        List<Customer > goods = customerService.list(page-1, rows, customerName );
        resultMap.put("total", customerService.count());
        resultMap.put("rows", goods);
        return resultMap;
    }

    @PostMapping("/save")
    public ServiceVO save(Customer customer) {
        Boolean save = customerService.save(customer);
        ServiceVO serviceVO = new ServiceVO<>(100, "请求成功");
        return serviceVO;
    }

    @PostMapping("/delete")
    public ServiceVO delete(@RequestParam String ids) {
        Boolean delete = customerService.delete(ids);
        ServiceVO serviceVO = new ServiceVO<>(100, "请求成功");
        return serviceVO;
    }
}
